<?php
include_once(DAO_PATH . "/ComponentDAO.php");
include_once(OBJECT_PATH . "/Component.php");

?>

<div class="form-title">Enter the details of the new component:</div>

<form id="addComponent" name="Add Component Form" method="post" action="components.php?action=add">

    <div class="form-label">Category:</div>
    <div class="form-component">
        <!-- Get the category from the database and populate the list -->
        <select name="category">
        <?php
            $dao = new ComponentDAO();
            $list = $dao->getCategoryList();

            // iterate through the ArrayObject list
            $iterator = $list->getIterator();
            while ($iterator->valid())
            {
                $category = $iterator->current();
                ?>
                <option value="<?php echo $category->getId(); ?>"><?php echo $category->getName(); ?></option>
                <?php
                $iterator->next();
            }
        ?>
        </select>
    </div>

    <div class="form-label">Name:</div>
    <div class="form-component">
        <input type="text" name="name" />
    </div>

    <div class="form-label">Description:</div>
    <div class="form-component">
        <input type="text" name="description" />
    </div>

    <div class="form-label">Current Stock:</div>
    <div class="form-component">
        <input type="text" name="stock" />
    </div>

    <div class="form-label">Price:</div>
    <div class="form-component">
        <input type="text" name="price" />
    </div>

    <div style="text-align: center;">
        <input type="submit" value="Submit" />
        <input type="reset" value="Reset" />
    </div>

</form>
